﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FlexiCommerce.Components;
using AjaxControlToolkit;


namespace FlexiCommerce.Web.Admin.FlexiAdmin.DynamicData.CustomPages.Category
{
    public partial class Details : System.Web.UI.Page
    {

        protected override void OnInit(EventArgs e)
        {
           
            FlexiCommerce.Components.Category cat = Find.Categories.Single(c => c.ID == int.Parse(Request.QueryString["ID"]));
            foreach (Culture culture in FlexiCommerce.Context.LocalizationManager.ConfiguredCultures())
            {
                if (cat.Details.SingleOrDefault(c => c.Culture.Name == culture.Name) == null)
                {
                    cat.AddDetail(new CategoryDetails("","",culture));
                    FlexiCommerce.Context.Persister.Save(cat);
                }
                
                TabPanel panel = new TabPanel();
                panel.HeaderText = culture.CultureInfo.DisplayName;
                panel.ID = culture.CultureInfo.Name;

                FlexiCommerce.Web.Admin.FlexiAdmin.DynamicData.Content.CategoryDetails control = (FlexiCommerce.Web.Admin.FlexiAdmin.DynamicData.Content.CategoryDetails)Page.LoadControl("~/FlexiAdmin/DynamicData/Content/CategoryDetails.ascx");
                control.ID = culture.CultureInfo.Name;
                control.DetailsType = typeof(Components.CategoryDetails);
                control.DetailsID = cat.Details.SingleOrDefault(d => d.Culture.Equals(culture)).ID;
                panel.Controls.Add(control);

                TabContainer1.Tabs.Add(panel);
            }
            if (!Page.IsPostBack)
            {
                TabContainer1.ActiveTabIndex = 0;
            }
            base.OnInit(e);

        }
        protected override void OnLoad(EventArgs e)
        { 
            base.OnLoad(e);
        }
    }
}
